package string;
/**
 * 设计方法，截取网址中的域名
 */
public class Test {
    public static void main(String[] args) {
        String s1 = "www.tedu.cn";
        String s2 = "http://www.tarena.com.cn";
        String s3 = "https://tts10.tmooc.cn/#/homework/index";
        String name1 = getHostName(s1);
        String name2 = getHostName(s2);
        String name3 = getHostName(s3);
        System.out.println(name1); //tedu
        System.out.println(name2); //tarena
        System.out.println(name3); //tmooc
    }

    public static String getHostName(String url) {
        int start = url.indexOf(".") + 1;       //11
        int end = url.indexOf("." ,start);  //17
        return url.substring(start, end);   //返回域名
    }
}
